<template>
	<view>
		<view class="padding-lr-lg">
			<view class="card">
				<view class="title">
					{{hold.product.product_name}}
				</view>
				<view class="info">
					<view>
						<text class="green">{{hold.gain}}</text> 静态
					</view>
					<view>
						<text class="green">{{hold.coin_type}}</text>
					</view>
					<button class="cu-btn bg-green round" @click="showmodal">{{hold.status==2?'已结束':'退出'}}</button>
				</view>
				<view class="rate">
					<text>日收益率{{hold.product.cft_rate}}%</text>
					<text>质押期限{{hold.product.duration}}天</text>
					<text>质押金额{{hold.coin_amount}}</text>
				</view>
			</view>
		</view>
		
		<view class="padding-lr" style="background: #292A45;">
			<view class="block-title active">
				<view class="title">
					<text class="text-white">收益记录（已进行收益{{logs.length}}天）</text>
				</view>
			</view>
		</view>
		
		<view class="list padding">
			<view class="row" v-for="i in logs" :key="i.id">
				<view class="time">
					{{i.created_at}} &nbsp&nbsp&nbsp&nbsp 静态
				</view>
				
				<view class="change">
					+{{i.amount}}
				</view>
			</view>
		</view>
		
		<u-modal v-model="modal" show-cancel-button @confirm="logout" :content="day=='-1'?content1:content2"></u-modal>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				hold: '',
				logs: [],
				day: '',
				content1: '确定要退出该质押产品吗？',
				content2: '确定要退出该质押产品吗？当前质押期限未满，需扣除一定手续费。',
				modal: false
			};
		},
		onLoad(opt) {
			this.id = opt.id
			this.getDetail();
		},
		methods: {
			getDetail() {
				this.$u.get('/cft/hold/log?trade_no='+this.id).then(res => {
					let data = res.data.result
					this.hold = data.hold
					this.logs = data.logs
					this.day = data.day
				})
			},
			showmodal() {
				if (this.hold.status==2) {
					
				} else {
					this.modal = true
				}
			},
			logout() {
				this.$u.get('/cft/quit?trade_no='+this.id).then(res => {
					uni.showToast({
						icon: 'none',
						title: '操作成功'
					})
					this.getDetail();
				})
			}
		}
	}
</script>

<style lang="scss">
	.card {
		color: #D6D6D7;
		background: #1B1B3B;
		padding: 20rpx 30rpx;
		border-radius: 20rpx;
		margin-bottom: 30rpx;
		line-height: 2;
		display: flex;
		flex-direction: column;
	
		.title {
			font-size: 32rpx;
			font-family:Source Han Sans CN;
			letter-spacing: 2rpx;
			color: #fff;
		}
	
		.info {
			display: flex;
			color: #fff;
			justify-content: space-between;
			align-items: center;
			font-size: 24rpx;
			
			.green {
				font-size: 40rpx;
				color: #00D28B;
				margin-right: 10rpx;
			}
		}
		
		.rate {
			margin-top: 10rpx;
			font-size: 20rpx;
			display: flex;
			justify-content: space-between;
		}
	
		.cu-btn {
			background: #00D28B;
		}
	}
	
	.row {
		display: flex;
		justify-content: space-between;
		font-size: 30rpx;
		margin-bottom: 30rpx;
		color: #B8B8BF;
		.change {
			color: #00D388;
		}
	}
</style>
